package com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.util;

import com.xyht.sca_s.student_manage_system.modules.org.entity.SmsOrgStructure;
import com.xyht.sca_s.student_manage_system.modules.org.mapper.SmsOrgStructureMapper;
import com.xyht.sca_s.student_manage_system.modules.user.entity.SmsUser;
import com.xyht.sca_s.student_manage_system.modules.user.mapper.SmsUserMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isNullOrEmpty;

/**
 * 二级学院负责人
 */
@Component
public class SecondaryCollegeLeaderUtil {

    @Resource
    private SmsOrgStructureMapper smsOrgStructureMapper;
    @Resource
    private SmsUserMapper smsUserMapper;

    /**
     *
     * @param orgId 学院组织id
     * @return 二级学院负责人userId
     */
    public String getSecondaryCollegeLeader(String orgId){
        if (isNullOrEmpty(orgId)) {
            return null;
        }

        //校验组织
        SmsOrgStructure smsOrgStructure = smsOrgStructureMapper.selectById(orgId);
        if (isNullOrEmpty(smsOrgStructure)) {
            return null;
        }

        //组织负责人id
        String leaderId = smsOrgStructure.getLeader();
        SmsUser smsUser = smsUserMapper.selectById(leaderId);
        if (isNullOrEmpty(smsUser)) {
            return null;
        }
        return leaderId;
    }
}
